import { Component, Prop } from 'vue-facing-decorator'
import Render from '@/render/Render'
import toNative from '@/utils/toNative'
import TableRender, { type TableRenderColumnTypes } from '@/render/TableRender'
import type { PageDto } from '@/api/types'
import type { AnyObject } from '@/types'
import { getInsureEnsurePlanList } from '@/api/insureEnsurePlan'
import type { InsureCompanyDetailDto } from '@/api/insCompany/types'
import type { InsureEnsurePlanListDto } from '@/api/insureEnsurePlan/types'
import { FeeDeductionRuleTypeCnEnum, InsureEnsureStatusCnEnum, ValidRuleTypeCnEnum } from '@/const/enum'

@Component
export class SystemSchemeView extends TableRender {
    @Prop() detailData!: InsureCompanyDetailDto

    noTablePadding = true
    tableColumnConfigOld = () => [
        {
            field: 'planCode',
            title: '方案编码',
        },
        {
            field: 'planName',
            title: '方案简称',
        },
        {
            field: 'companyName',
            title: '保司方案',
        },
        {
            field: 'effectType',
            title: '生效方式',
            formatter: ({row}) => {
                return ValidRuleTypeCnEnum[row.effectType]
            }
        },
        {
            field: 'insurePlanType',
            title: '保单类型',
            formatter: ({row}) => {
                return FeeDeductionRuleTypeCnEnum[row.insurePlanType]
            }
        },
        {
            field: 'status',
            title: '状态',
            params: {
                tags: {
                    0: 'processing',
                    1: 'success',
                    2: 'error'
                }
            },
            formatter: ({row}) => {
                return InsureEnsureStatusCnEnum[row.status]
            },
            slots: {
                default: 'colorTag'
            }
        }
    ] as TableRenderColumnTypes<InsureEnsurePlanListDto>

    onLoadData(pageNum: number, pageSize: number, filters: AnyObject) {
        return getInsureEnsurePlanList({
            pageNum,
            pageSize,
            insureCompanyId: this.detailData.id,
            ...filters
        })
    }

    render() { 
        return (
            <div class="h-full flex flex-col">
                {super.renderTable()}
            </div>
        )
    }
}

export default toNative<{detailData: InsureCompanyDetailDto}, {}>(SystemSchemeView)